<?php
namespace app\admin\controller;
use think\Controller;
class Login extends Controller
{
    //后台管理登陆首页
    public function index()
    {
        $uid = session('user')['id'];
        if($uid){
            $this->redirect('total/index');
        }else{
            return $this->fetch('login/login');
        }
    }

    //登陆方法
    public function dologin()
    {
        $json = array();
        $data = input('post.');
        $data['password'] = $data['password'];
        $hospital = db('user')->where('username',$data['username'])->where('password',$data['password'])->find();
        if(!captcha_check($data['verify'])){
            $json['msg'] = '验证码错误';
            $json['status'] = '201';
        }elseif(!$hospital){
            $json['msg'] = '账号密码错误';
            $json['status'] = '201';
        }else{
            session('user',$hospital);
            $json['msg'] = '';
            $json['status'] = '200';
        }
        echo json_encode($json);
    }

    //退出登录
    public function logout()
    {
        // 清除session
        session('user',null);
        // 跳出
        $this->redirect('login/index');
    }




}